<?php
//前台函数库

//获取col_id
function getcol_id($tablename){
  $syscolumn=M("syscolumn");
  $col_id=$syscolumn->where("col_eng_name='$tablename'")->getField("id");
  return $col_id;
}
//根据typename求出typeid
function gettypeidbytypename($typename,$table){
   $col_id=getcol_id($table);
   
   $sysclass=M("sysclass");
   return $sysclass->where("col_id=$col_id and class_name='$typename'")->getField("id");
}
//根据typeid求出typename
function gettypenamebytypeid($typeid){
  $sysclass=M("sysclass");
  return $sysclass->where("id=$typeid")->getField("class_name");
}
//根据typeid求出父类typename  
function getpar_typenamebytypeid($typeid){
  $sysclass=M("sysclass");
  $parid=$sysclass->where("id=$typeid")->getField("parid");
  return $sysclass->where("id=$parid")->getField("class_name");
}
//根据typeid求出en_typename 如果存在en_class_name
function geten_typenamebytypeid($typeid){
  $sysclass=M("sysclass");
  return $sysclass->where("id=$typeid")->getField("en_class_name");
}
//获取文章列表根据typename
function get_articlebytypename($typename,$num){
  $col_id=getcol_id("article");
  $typeid=gettypeidbytypename($typename,"article");
  $article=M("article");
  $map["typeid"]=array("in",typeid2child($typeid,"sysclass",$col_id));
  return $article->where($map)->limit($num)->order("sequence desc")->findAll();
}
//获取文章列表根据typeid
function get_articlebytypeid($typeid,$num){ 
  $col_id=getcol_id("article");
  $article=M("article");
  $map["typeid"]=array("in",typeid2child($typeid,"sysclass",$col_id));
  return $article->where($map)->limit($num)->order("sequence desc")->findAll();
}
//获取系统sysclass的类别下拉
function get_mult_type_select($tablename,$select_value=0,$typeid=0){
    $col_id=getcol_id($tablename);
	if(empty($col_id)) return false;
	$item_arr=create_cascade_item("sysclass",$typeid,"class_name","col_id=$col_id");
	return show_cascade_item($item_arr,$select_value);
}
//处理后台图片集
//图片集值 返回对应数组 array("pic"=>"","text"=>"","link"=>"")
function pics_arr($pics){
	if(empty($pics))return false;
	$pics_arr=explode("@",$pics);
	$return_arr["pic"]=explode(",",$pics_arr[0]);
	$return_arr["text"]=explode(",",$pics_arr[1]);
	$return_arr["link"]=explode(",",$pics_arr[1]);
	return $return_arr;
}
//数组 模板赋值
//使用时 需要在Action中添加 如下函数
/*
public function assign($name,$value){
   parent::assign($name,$value);	
}
*/
function assign_output($output_arr,&$obj){
	if(!is_array($output_arr))exit;
	
	foreach($output_arr as $key => $val){
		$obj->assign($key,$val);
	}
	
}
?>